package com.tencent.stat;

import com.tencent.stat.common.StatLogger;
import com.tencent.stat.event.d;

class ap
  implements Thread.UncaughtExceptionHandler
{
  public void uncaughtException(Thread paramThread, Throwable paramThrowable)
  {
    if ((!(StatConfig.isEnableStatService())) || (StatServiceImpl.e() == null))
      return;
    while (true)
    {
      try
      {
        do
        {
          if (!(StatConfig.isAutoExceptionCaught()))
            break label129;
          aw.a(StatServiceImpl.e()).a(new d(StatServiceImpl.e(), StatServiceImpl.a(StatServiceImpl.e(), false, null), 2, paramThrowable, paramThread, null), null, false, true);
          StatServiceImpl.f().debug("MTA has caught the following uncaught exception:");
          StatServiceImpl.f().error(paramThrowable);
          StatServiceImpl.flushDataToDB(StatServiceImpl.e());
          if (StatServiceImpl.g() == null)
            continue;
          StatServiceImpl.f().d("Call the original uncaught exception handler.");
          if (StatServiceImpl.g() instanceof ap)
            continue;
          StatServiceImpl.g().uncaughtException(paramThread, paramThrowable);
        }
        while (StatConfig.d() == null);
        StatConfig.d().onMtaException(paramThrowable);
        return;
      }
      catch (Throwable paramThread)
      {
        paramThread.printStackTrace();
        return;
      }
      label129: StatServiceImpl.f().w("crash happened, but MTA AutoExceptionCaught is desable.");
    }
  }
}